package com.czq.cn.controller;

import com.czq.cn.entity.Product;
import com.czq.cn.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @PostMapping("/add")
    public String add(@RequestBody Product product){
        productService.addProduct(product);
        return "add product success";
    }

    @PostMapping("/update")
    public String update(@RequestBody Product product) {
        productService.updateProduct(product);
        return "update product success";
    }

    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable Long id) {
        productService.delete(id);
        return "delete product success";
    }

    @GetMapping("/detail/{id}")
    public Product detail(@PathVariable Long id) {
        return productService.detail(id);
    }

}



